package 预科0104UserMessage_Q4;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import 预科0104UserMessage_Q4.UserMessage.User;

public class UserMessageServer {
	public static void main(String[] args) {
		ServerSocket ss=null;
		Socket sc=null;
		try {
			ss=new ServerSocket(8888);
			sc=ss.accept();
			System.out.println("连接");
			ObjectInputStream oi = new ObjectInputStream(sc.getInputStream());
			UserMessage um=(UserMessage)oi.readObject();
			if(um.getUser().getName().equalsIgnoreCase("admin")&&um.getUser().getPassword().equalsIgnoreCase("123456")) {
				um.setType("success");
			}else {
				um.setType("fail");
			}
			ObjectOutputStream oo=new ObjectOutputStream(sc.getOutputStream());
			oo.writeObject(um);
			System.out.println(um.getType().equals("success")?"登录成功":"登录失败");
		} catch (IOException | ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				sc.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	
}